package com.yuwubao.uav.tool.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yuwubao.framework.bean.JsonResult;
import com.yuwubao.framework.bean.PageData;
import com.yuwubao.framework.loginFilter.CurrentUserConstants;
import com.yuwubao.framework.loginFilter.LoginRequired;
import com.yuwubao.uav.tool.service.*;
import com.yuwubao.uav.tool.util.Sendmail;
import com.yuwubao.uav.tool.util.StringUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Min;
import java.io.File;
import java.util.Date;

/**
 * 官网页面展示
 */
@RestController
@RequestMapping("/front")
public class FrontController {

    private static final Logger logger = LogManager.getLogger(FrontController.class);

    private static final String BASE_PATH = "/zhiku";

    private static final String BASE_URL = "http://47.93.158.24:8780";

    @Resource
    private FrontService frontService;

    @GetMapping("/listFile")
    @ApiOperation(value = "获取文件列表")
    public JsonResult listFile(
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listFile(pageData));
            result.setResultNum(frontService.listFileCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listViewpoint")
    @ApiOperation(value = "获取学者观点列表")
    public JsonResult listViewpoint(
            @ApiParam(value = "类型ID") @RequestParam(name="typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("typeId", typeId);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listViewpoint(pageData));
            result.setResultNum(frontService.listViewpointCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listViewpointTypeAll")
    @ApiOperation(value = "获取学者观点类型列表所有")
    public JsonResult listViewpointTypeAll(
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listViewpointTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listTtResult")
    @ApiOperation(value = "获取智库成果列表")
    public JsonResult listTtResult(
            @ApiParam(value = "类型ID") @RequestParam(name="typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("typeId", typeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listTtResult(pageData));
            result.setResultNum(frontService.listTtResultCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listTtResultTypeAll")
    @ApiOperation(value = "获取智库成果类型列表所有")
    public JsonResult listTtResultTypeAll(
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listTtResultTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listThinkTank")
    @ApiOperation(value = "获取专业智库列表")
    public JsonResult listThinkTank(
            @ApiParam(value = "分类ID") @RequestParam(value = "typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("typeId", typeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listThinkTank(pageData));
            result.setResultNum(frontService.listThinkTankCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listThinkTankTypeAll")
    @ApiOperation(value = "获取专业智库类型列表所有")
    public JsonResult listThinkTankTypeAll(
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listThinkTankTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }


    @GetMapping("/listSpecialG")
    @ApiOperation(value = "获取决策专刊列表-分组版")
    public JsonResult listSpecialG(
            @ApiParam(value = "类型ID") @RequestParam(name="typeId",required = false) String typeId,
            @ApiParam(value = "决策专刊类型父类型ID") @RequestParam(value = "fatherTypeId",required = false) String fatherTypeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("typeId", typeId);
            pageData.put("fatherTypeId", fatherTypeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listSpecialG(pageData));
            result.setResultNum(frontService.listSpecialGCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }
    @GetMapping("/listSpecial")
    @ApiOperation(value = "获取决策专刊列表")
    public JsonResult listSpecial(
            @ApiParam(value = "类型ID") @RequestParam(name="typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("typeId", typeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listSpecial(pageData));
            result.setResultNum(frontService.listSpecialCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listSpecialTypeAll")
    @ApiOperation(value = "获取决策专刊类型列表所有")
    public JsonResult listSpecialTypeAll(
            @ApiParam(value = "决策专刊类型父类型id", required = true) @RequestParam("fid") String fid,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("fid", fid);

            result.setResult(frontService.listSpecialTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }
    @GetMapping("/listSpecialTypeFatherAll")
    @ApiOperation(value = "获取决策专刊类型父类型列表所有")
    public JsonResult listSpecialTypeFatherAll(
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listSpecialTypeFatherAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listProfessor")
    @ApiOperation(value = "获取专家列表")
    public JsonResult listProfessor(
            @ApiParam(value = "姓氏首字母") @RequestParam(value = "nameChar",required = false) String nameChar,
            @ApiParam(value = "类型0:根据名称 1：根据领域 2：根据部门") @RequestParam(value = "typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("typeId", typeId);
            pageData.put("nameChar", nameChar);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listProfessor(pageData));
            result.setResultNum(frontService.listProfessorCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listPaterner")
    @ApiOperation(value = "获取合作单位列表")
    public JsonResult listPaterner(
            @ApiParam(value = "类型Id") @RequestParam(value = "typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("typeId", typeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listPaterner(pageData));
            result.setResultNum(frontService.listPaternerCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }
    @GetMapping("/listPaternerTypeAll")
    @ApiOperation(value = "获取合作单位类型列表")
    public JsonResult listPaternerTypeAll() {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();

            result.setResult(frontService.listPaternerTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listMedia")
    @ApiOperation(value = "获取音频视频音频视频文件列表")
    public JsonResult listMedia(
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listMedia(pageData));
            result.setResultNum(frontService.listMediaCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listHotNews")
    @ApiOperation(value = "获取热点资讯列表")
    public JsonResult listHotNews(
            @ApiParam(value = "类型ID") @RequestParam(name="typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("typeId", typeId);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listHotNews(pageData));
            result.setResultNum(frontService.listHotNewsCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }
    @GetMapping("/listHotNewsSlide")
    @ApiOperation(value = "获取热点资讯轮播图列表")
    public JsonResult listHotNewsSlide(
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();

            result.setResult(frontService.listHotNewsSlide(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listHotNewsTypeAll")
    @ApiOperation(value = "获取要闻类型列表所有")
    public JsonResult listHotNewsTypeAll(
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listHotNewsTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listForum")
    @ApiOperation(value = "获取会议论坛列表")
    public JsonResult listForum(
            @ApiParam(value = "类型ID") @RequestParam(name = "typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("typeId", typeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listForum(pageData));
            result.setResultNum(frontService.listForumCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listForumTypeAll")
    @ApiOperation(value = "获取会议论坛类型列表所有")
    public JsonResult listForumTypeAll(
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listForumTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listDecisionComment")
    @ApiOperation(value = "获取决策调研评论列表-前端显示使用")
    public JsonResult listDecisionComment(
            @ApiParam(value = "决策ID") @RequestParam(value = "decisionId",required = false) String decisionId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("decisionId", decisionId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listDecisionComment(pageData));
            result.setResultNum(frontService.listDecisionCommentCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listDecision")
    @ApiOperation(value = "获取决策调研列表")
    public JsonResult listDecision(
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listDecision(pageData));
            result.setResultNum(frontService.listDecisionCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @LoginRequired
    @PostMapping("/addDecisionComment")
    @ApiOperation(value = "新增决策调研评论")
    public JsonResult addDecisionComment(
            @ApiParam(value = "决策调研ID", required = true) @RequestParam("decisionId") String decisionId,
            @ApiParam(value = "评论用户ID", required = true) @RequestParam("id") String userId,
            @ApiParam(value = "内容") @RequestParam(value = "content",required = false) String content
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("content", content);
            pageData.put("userId", userId);
            pageData.put("decisionId", decisionId);

            frontService.addDecisionComment(pageData);

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }


    @GetMapping("/listCourse")
    @ApiOperation(value = "获取课题列表")
    public JsonResult listCourse(

            @ApiParam(value = "类型ID") @RequestParam(name="typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("typeId", typeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listCourse(pageData));
            result.setResultNum(frontService.listCourseCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listCourseTypeAll")
    @ApiOperation(value = "获取课题类型列表")
    public JsonResult listCourseTypeAll(
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listCourseTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }


    @GetMapping("/listAdvice")
    @ApiOperation(value = "获取通知列表")
    public JsonResult listAdvice(
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listAdvice(pageData));
            result.setResultNum(frontService.listAdviceCount(pageData));

            try {
                //总访问量
                frontService.addTotalTimes();
            } catch (Exception e) {
                e.printStackTrace();
            }

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }


    @GetMapping("/listAdver")
    @ApiOperation(value = "获取广告列表")
    public JsonResult listAdver(
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 2) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "广告类型 1:图片广告  2：专题广告")@RequestParam(value = "type",required = false) String type,
            @ApiParam(value = "广告位置 0:顶部 1:上  2：中 3：下 4:轮播图",required = true)@RequestParam(value = "position",required = true) String position,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("type", type);
            pageData.put("position", position);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listAdver(pageData));
            result.setResultNum(frontService.listAdverCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listFocusNews")
    @ApiOperation(value = "获取要闻列表")
    public JsonResult listFocusNews(
            @ApiParam(value = "类型ID") @RequestParam(value = "typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("typeId", typeId);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listFocusNews(pageData));
            result.setResultNum(frontService.listFocusNewsCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listFocusNewsTypeAll")
    @ApiOperation(value = "获取要闻类型列表所有")
    public JsonResult listFocusNewsTypeAll(
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listFocusNewsTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listMenu")
    @ApiOperation(value = "获取首页菜单列表")
    public JsonResult listMenu() {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            result.setSuccessful();
        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/getAllianceInfo")
    @ApiOperation(value = "获取关于联盟")
    public JsonResult getAllianceInfo() {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            result.setResult(frontService.getAllianceInfo(pageData));
            result.setSuccessful();
        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listAllianceActivity")
    @ApiOperation(value = "获取联盟活动列表")
    public JsonResult listAllianceActivity(
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listAllianceActivity(pageData));
            result.setResultNum(frontService.listAllianceActivityCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listAllianceMember")
    @ApiOperation(value = "获取联盟成员列表")
    public JsonResult listAllianceMember(
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();

            result.setResult(frontService.listAllianceMember(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/getOrgInfo")
    @ApiOperation(value = "获取关于联盟成员")
    public JsonResult getOrgInfo(
            @ApiParam(value = "成员ID",required = true) @RequestParam(value = "id") String id
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("id",id);
            result.setResult(frontService.getOrgInfo(pageData));
            result.setSuccessful();
        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listOrgDynamic")
    @ApiOperation(value = "获取动态列表")
    public JsonResult listOrgDynamic(
            @ApiParam(value = "机构ID") @RequestParam(value = "orgId",required = false) String orgId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("orgId", orgId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listOrgDynamic(pageData));
            result.setResultNum(frontService.listOrgDynamicCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listOrgProject")
    @ApiOperation(value = "获取研究项目列表")
    public JsonResult listOrgProject(
            @ApiParam(value = "分类ID") @RequestParam(value = "typeId",required = false) String typeId,
            @ApiParam(value = "机构ID") @RequestParam(value = "orgId",required = false) String orgId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("orgId", orgId);
            pageData.put("typeId", typeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listOrgProject(pageData));
            result.setResultNum(frontService.listOrgProjectCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listOrgProjectTypeAll")
    @ApiOperation(value = "获取研究项目类型列表所有")
    public JsonResult listOrgProjectTypeAll(
            @ApiParam(value = "机构ID",required = true) @RequestParam(value = "orgId") String orgId,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("orgId", orgId);
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listOrgProjectTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listOrgResult")
    @ApiOperation(value = "获取研究成果列表")
    public JsonResult listOrgResult(
            @ApiParam(value = "分类ID") @RequestParam(value = "typeId",required = false) String typeId,
            @ApiParam(value = "机构ID") @RequestParam(value = "orgId",required = false) String orgId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("orgId", orgId);
            pageData.put("typeId", typeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listOrgResult(pageData));
            result.setResultNum(frontService.listOrgResultCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listOrgResultTypeAll")
    @ApiOperation(value = "获取研究成果类型列表所有")
    public JsonResult listOrgResultTypeAll(
            @ApiParam(value = "机构ID",required = true) @RequestParam(value = "orgId") String orgId,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("orgId", orgId);
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listOrgResultTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listOrgPublish")
    @ApiOperation(value = "获取出版物列表")
    public JsonResult listOrgPublish(
            @ApiParam(value = "分类ID") @RequestParam(value = "typeId",required = false) String typeId,
            @ApiParam(value = "机构ID") @RequestParam(value = "orgId",required = false) String orgId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("orgId", orgId);
            pageData.put("typeId", typeId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listOrgPublish(pageData));
            result.setResultNum(frontService.listOrgPublishCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }


    @GetMapping("/listOrgPublishTypeAll")
    @ApiOperation(value = "获取出版物类型列表所有")
    public JsonResult listOrgPublishTypeAll(
            @ApiParam(value = "机构ID",required = true) @RequestParam(value = "orgId") String orgId,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("orgId", orgId);
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listOrgPublishTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listOrgJg")
    @ApiOperation(value = "获取单位机构列表")
    public JsonResult listOrgJg(
            @ApiParam(value = "智库机构ID") @RequestParam(value = "orgId",required = false) String orgId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("orgId", orgId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listOrgJg(pageData));
            result.setResultNum(frontService.listOrgJgCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listOrgLeader")
    @ApiOperation(value = "获取领导列表")
    public JsonResult listOrgLeader(
            @ApiParam(value = "智库机构ID") @RequestParam(value = "orgId",required = false) String orgId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("orgId", orgId);
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listOrgLeader(pageData));
            result.setResultNum(frontService.listOrgLeaderCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listOrg")
    @ApiOperation(value = "获取智库名录列表")
    public JsonResult listOrg(
            @ApiParam(value = "智库机构首字母，如A,B,...") @RequestParam(value = "nameChar",required = false) String nameChar
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("nameChar",nameChar);

            result.setResult(frontService.listOrg(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }


    /*
    @GetMapping("/clickOrgDynamic")
    @ApiOperation(value = "点击动态事件")
    public JsonResult clickOrgDynamic(
            @ApiParam(value = "动态ID", required = true) @RequestParam("id") String id
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("id", id);

            frontService.clickOrgDynamic(pageData);

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/clickOrgProject")
    @ApiOperation(value = "点击研究项目事件")
    public JsonResult clickOrgProject(
            @ApiParam(value = "研究项目ID", required = true) @RequestParam("id") String id
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("id", id);

            frontService.clickOrgProject(pageData);

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/clickOrgPublish")
    @ApiOperation(value = "点击出版物事件")
    public JsonResult clickOrgPublish(
            @ApiParam(value = "出版物ID", required = true) @RequestParam("id") String id
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("id", id);

            frontService.clickOrgPublish(pageData);

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/clickOrgResult")
    @ApiOperation(value = "点击研究成果事件")
    public JsonResult clickOrgResult(
            @ApiParam(value = "研究成果ID", required = true) @RequestParam("id") String id
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("id", id);

            frontService.clickOrgResult(pageData);

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/clickTtResult")
    @ApiOperation(value = "点击智库成果事件")
    public JsonResult clickTtResult(
            @ApiParam(value = "智库成果ID", required = true) @RequestParam("id") String id
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("id", id);

            frontService.clickTtResult(pageData);

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/clickViewpoint")
    @ApiOperation(value = "点击学者观点事件")
    public JsonResult clickViewpoint(
            @ApiParam(value = "学者观点ID", required = true) @RequestParam("id") String id
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("id", id);

            frontService.clickViewpoint(pageData);

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }
    */

    @LoginRequired
    @ApiOperation (value = "决策调研问卷提交")
    @PostMapping("/uploadFile")
    public JsonResult uploadFile(
            @ApiParam(value = "上传的文件") @RequestParam(value = "fileName") MultipartFile file,
            @ApiParam(value = "决策ID",required = true) @RequestParam(value = "id") String id,
            @ApiParam(value = "用户ID",required = true) @RequestParam(value = "userId") String userId,
            HttpServletRequest request
    ) {
        JsonResult result = new JsonResult();
        try {
            // 原始名称
            String originalFilename = file.getOriginalFilename();

//            String originName = originalFilename.substring(0,originalFilename.lastIndexOf("."));
            String originSuffix = originalFilename.substring(originalFilename.lastIndexOf("."),originalFilename.length());

            // 存储图片的物理路径
            String filePath = new File(request.getSession().getServletContext().getRealPath("")).getParent() + BASE_PATH;

            File dir = new File(filePath);
            if (!dir.exists()) {
                dir.mkdirs();
            }

            // 将内存中的数据写入磁盘
            String newFileName = "doc" + "_" + new Date().getTime() + originSuffix;
            file.transferTo(new File(filePath + "/" + newFileName));

            System.out.println(filePath);

            PageData rePd = new PageData();
            rePd.put("originName",originalFilename);
            rePd.put("storageName",BASE_URL + BASE_PATH + "/" + newFileName);
            rePd.put("userId",userId);
            rePd.put("id",id);

            frontService.addDecisionResponse(rePd);

            result.setSuccessful();


        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }
        return result;
    }

    @GetMapping("/listQuestionnaire")
    @ApiOperation(value = "获取问卷列表")
    public JsonResult listQuestionnaire(
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listQuestionnaire(pageData));
            result.setResultNum(frontService.listQuestionnaireCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/getQuestionnaireInfo")
    @ApiOperation(value = "获取问卷详情")
    public JsonResult getQuestionnaireInfo(
            @ApiParam(value = "问卷ID",required = true) @RequestParam(value = "qId") String qId
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("qId", qId);

            result.setResult(frontService.getQuestionnaireInfo(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @PostMapping("/answerQuestionnaire")
    @ApiOperation(value = "回答问卷")
    public JsonResult answerQuestionnaire(
            @ApiParam(value = "问卷ID",required = true) @RequestParam(value = "qId") String qId,
            @ApiParam(value = "答案",required = true) @RequestParam(value = "qResultJsonStr") String qResultJsonStr
    ) {
        /*
        [
            {
                subjectId:题目序号
                optionIds:选择题IDS，多个用逗号隔开，问答题是文字
                subType:题目类型 1：选择题 2：填空题
            }
        ]
         */
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("qId", qId);
            pageData.put("qResultJsonStr", qResultJsonStr);
            JSONArray jsonArray = JSONObject.parseArray(qResultJsonStr);

            if (jsonArray != null) {
                String subType = null;
                String optionIds = null;
                JSONObject jsonObject = null;
                //更新问卷答题人数+1
                frontService.updateQResponseCount(pageData);
                for (Object object : jsonArray) {
                    try {
                        jsonObject = (JSONObject) object;

                        if (jsonObject != null) {
                            subType = jsonObject.get("subType") == null ? "" : jsonObject.get("subType").toString();
                            optionIds = jsonObject.get("optionIds") == null ? "" : jsonObject.get("optionIds").toString();

                            //更新问卷题目答题人数+1
                            pageData.put("subjectId",jsonObject.get("subjectId"));
                            frontService.updateQSubjectResponseCount(pageData);

                            if (StringUtil.isNotNvlOrBlank(subType)) {
                                //选择题
                                if ("1".equals(subType)) {
                                    String[] optionIdArr = optionIds.split(",");
                                    if (optionIdArr != null && optionIdArr.length > 0) {
                                        for (String optionId : optionIdArr) {
                                            pageData.put("optionId",optionId);
                                            //更新问卷题目选项选择答题人数+1
                                            frontService.updateQOptionResponseCount(pageData);
                                        }
                                    }
                                }
                                //填空题
                                if ("2".equals(subType)) {
                                    pageData.put("content",optionIds);
                                    //更新问卷题目选项选择答题人数+1
                                    frontService.updateQContentResponseCount(pageData);
                                }
                            }
                        }

                    }catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            }

            frontService.answerQuestionnaire(pageData);

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }


    @PostMapping("/userFindPasswd")
    @ApiOperation(value = "用户找回密码")
    public JsonResult userFindPasswd(
            @ApiParam(value = "邮箱",required = true) @NotEmpty @RequestParam(value = "mail") String mail
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("mail", mail);

            PageData userInfo = frontService.getUserPwdByMail(pageData);
            if (userInfo != null &&
                    userInfo.get("user_name") != null && StringUtil.isNotNvlOrBlank(userInfo.get("user_name").toString()) &&
                    userInfo.get("user_pwd_mw") != null && StringUtil.isNotNvlOrBlank(userInfo.get("user_pwd_mw").toString())) {
                //发送邮件到邮箱
                new Sendmail(
                        mail,
                        userInfo.get("user_name").toString(),
                        "湖北智库网用户密码找回",
                        "尊敬的用户"+userInfo.get("user_name").toString()+"您好：您的密码为<a>"+userInfo.get("user_pwd_mw").toString()+"</a>").start();

                result.setSuccessful("找回密码信息已经发送到您的邮箱，请查收！");
            } else {
                result.setFailure("该邮箱未注册过，请检查邮箱！");
            }

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/getSystemInfo")
    @ApiOperation(value = "获取系统信息")
    public JsonResult getSystemInfo(
    ) {
        JsonResult result = new JsonResult();
        try {
            result.setResult(frontService.getSystemInfo());
            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listEvaluationTypeAll")
    @ApiOperation(value = "获取智库评价类型列表所有")
    public JsonResult listEvaluationTypeAll(
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);

            result.setResult(frontService.listEvaluationTypeAll(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listEvaluation")
    @ApiOperation(value = "获取智库评价列表")
    public JsonResult listEvaluation(
            @ApiParam(value = "类型ID") @RequestParam(name="typeId",required = false) String typeId,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("typeId", typeId);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listEvaluation(pageData));
            result.setResultNum(frontService.listEvaluationCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listGNThinktank")
    @ApiOperation(value = "获取国内智库列表")
    public JsonResult listGNThinktank(
            @ApiParam(value = "智库类型 0：国内智库，1：海外智库",required = true) @RequestParam(name="type",defaultValue = "0") String type,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            if (type != null && !"".equals(type)) {
                if ("0".equals(type)) {
                    pageData.put("type", "国内智库");
                } else {
                    pageData.put("type", "海外智库");
                }
            }
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listGNThinktank(pageData));
            result.setResultNum(frontService.listGNThinktankCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listLearningMaterials")
    @ApiOperation(value = "获取学习资料列表")
    public JsonResult listLearningMaterials(
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {
            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));

            result.setResult(frontService.listLearningMaterials(pageData));
            result.setResultNum(frontService.listLearningMaterialsCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("/listUserPublish")
    @ApiOperation(value = "获取用户发布列表")
    public JsonResult listUserPublish(
            HttpServletRequest request,
            @ApiParam(value = "当前页", required = true) @Min(1) @Length(max = 8) @NotEmpty @RequestParam("page") String page,
            @ApiParam(value = "当前页数量", required = true) @Min(10) @Length(max = 3) @NotEmpty @RequestParam("pageSize") String pageSize,
            @ApiParam(value = "搜索关键字") @RequestParam(value = "searchKey",required = false) String searchKey
    ) {
        JsonResult result = new JsonResult();
        try {

            PageData pageData = new PageData();
            pageData.put("searchKey", searchKey);
            pageData.put("begin", (Integer.valueOf(page) - 1) * Integer.valueOf(pageSize));
            pageData.put("pageSize", Integer.valueOf(pageSize));
            Object userIdObj = request.getAttribute(CurrentUserConstants.CURRENT_USER);
            if (userIdObj != null) {
                pageData.put("userId",userIdObj.toString());
            }

            result.setResult(frontService.listUserPublish(pageData));
            result.setResultNum(frontService.listUserPublishCount(pageData));

            result.setSuccessful();

        } catch (Exception e) {
            logger.error("", e);
            result.setFailure(e.getMessage());
        }

        return result;
    }

    @GetMapping("getThemeAdType")
    JsonResult getThemeAdType() {
        JsonResult result = new JsonResult();

        return result;
    }


}
